<?php
require_once "WXconfig.php";

header("Content-type: text/html; charset=UTF-8");

// $content = 'amount=1.0&goodsName=中性笔&merchno=211440342140001&notifyUrl=http://120.79.146.234.6:8170/BusiM/AL002/TestUserQRCallBackServlet&payType=2&remark=中性笔&settleType=1&traceno=11m2p7iio7r9of97oiqoe4hcpe&';
// // $content = 'Hello';
// echo $content.'</br>';
// echo md5($content).'</br>';
// $data = $_GET['cc'];
// $payty =$_GET['paytype'];
// $gettype =$_GET['gettype'];
    //初始化

function doCurlPostRequest($paytype,$amount,$gettp,$timeout = 5){

$urls=Configs::URLPASSIVEPAY;
$Md5=Configs::SIGNATURE;
$merchnos=Configs::MERCHNO;
$timetraceno =Configs::TIMETRA.date('ymdhis',time());
//$timetraceno= '5vx45nwh5onmalpn6pyzjeouza';
$certno=Configs::CERTNO;
$notifyUrl=Configs::NOTIFYURL;
$accountno=Configs::ACCOUNTNO;
$mobile=Configs::MOBILE;
$account_name=Configs::ACCOUNT_NAME;
$fee=$amount*Configs::FEE;
    $goodNames='中性笔';
if($fee<0.01){
	$fee=0.01;
}
$pyte='';
$post_data='';
if($gettp=='1'){
	 $post_data = array(
    'merchno' => $merchnos,
    'amount' => $amount,
    'traceno' => $timetraceno,
    'payType' => $paytype,
    'certno'=>$certno,
    'accountno'=>$accountno,
    'account_name'=>$account_name,
    'fee'=>$fee,
    'notifyUrl'=>$notifyUrl,
    'settleType'=>'0',
    'mobile'=>$mobile,
    "goodsName"=>'商品名称',
    'remark'=>"remark"
);
}else{
		 $post_data = array(
    'merchno' => $merchnos,
    'amount' => $amount,
    'traceno' => $timetraceno,
    'payType' => $paytype,
    'notifyUrl'=>$notifyUrl,
    'goodsName'=>$goodNames,
    'settleType'=>'1',
    'remark'=>$goodNames
);
}

ksort($post_data);
$a='';
foreach($post_data as $x=>$x_value)
{
	$a=$a.$x."=".iconv('UTF-8', 'GB2312',$x_value)."&";
}
//    echo $goodNames.'</br></br>';
//    echo md5($goodNames).'</br></br>';
//    echo md5(iconv('UTF-8', 'GB2312', $goodNames)).'</br></br>';
    $md5Content = 'amount=50.0&goodsName=中性笔&merchno=211440342140001&notifyUrl=http://test.kftpay.com.cn/clearing-bank-callback10/cib/tradeCb&payType=1&remark=中性笔&settleType=1&traceno=iym4dh4770sow516peyrny7oop&5FD72D8C799B7D2AED41893355EBB147';
//    echo $md5Content;
//    echo '</br></br>'.md5(iconv('UTF-8', 'GB2312',$md5Content)).'</br></br>';

echo '</br>'.htmlspecialchars($a.$Md5,ENT_COMPAT, 'GB2312').'</br></br>';
$b=md5($a.$Md5);
echo '</br>'.$b.'</br>';
$c=$a.'signature'.'='.$b;
 if($urls == '' || $c == '' || $timeout <=0){
 return false;
 }
 echo $c.'</br>';
//    $urls = 'http://localhost:8087/moulde-insert/BussinessInfoCRUD/test.do';
//    $c = $c."&method=test";
  $con = curl_init((string)$urls);
  curl_setopt($con, CURLOPT_HEADER, false);
  curl_setopt($con, CURLOPT_POSTFIELDS, $c);
  curl_setopt($con, CURLOPT_POST,true);
  curl_setopt($con, CURLOPT_RETURNTRANSFER,true);
  curl_setopt($con, CURLOPT_TIMEOUT,(int)$timeout);
  return curl_exec($con);
}
// function doCurlPostRequest($paytype,$amount,$gettp,$timeout = 5){
echo iconv('GB2312', 'UTF-8', doCurlPostRequest('1','50.0','2'));

?>